package com.zmn.plat.services.impl.part;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.pager.LayuiPageUtil;
import com.zmn.mcc.cas.model.LoginStaff;
import com.zmn.plat.model.entity.part.PartSkuPrice;
import com.zmn.plat.model.entity.part.PartSkuPriceQuery;
import com.zmn.plat.persistence.interfaces.part.PartSkuPriceDAO;
import com.zmn.plat.services.interfaces.part.PartSkuPriceService;

/**
 * @author nowind
 * @since 17/06/12 12:22
 */
@Service
public class PartSkuPriceServiceImpl implements PartSkuPriceService {
    private Logger logger = LoggerFactory.getLogger(PartSkuPriceServiceImpl.class);

    @Resource
    private PartSkuPriceDAO partSkuPriceDAO;

    /*========== PartSkuPrice ==========*/

    /**
     * 描述:通过ID查
     *
     * @param skuId
     *            ID
     * @return PartSkuPrice
     * @author DaiZhichao
     * @since 2018/10/23 16:33
     */
    @Override
    public PartSkuPrice findByKey(Integer skuId) {
        return partSkuPriceDAO.findByKey(skuId);
    }

    /**
     * 描述:通过查询对象分页查询
     *
     * @param query
     *            查询对象
     * @return List<PartSkuPrice>
     * @author DaiZhichao
     * @since 2018/10/23 16:34
     */
    @Override
    public List<PartSkuPrice> listPageByQuery(PartSkuPriceQuery query) {
        Integer count = this.countByQuery(query);
        query.setTotalCount(count);
        return count == 0 ? new ArrayList<>(0) : partSkuPriceDAO.listPageByQuery(new LayuiPageUtil<>(query).setLayuiPage().setStartEndTime().getQuery());
    }

    /**
     * 描述:通过查询对象查询
     *
     * @param query
     *            查询对象
     * @return List<PartSkuPrice>
     * @author DaiZhichao
     * @since 2018/10/23 16:34
     */
    @Override
    public List<PartSkuPrice> listByQuery(PartSkuPriceQuery query) {
        return partSkuPriceDAO.listByQuery(new LayuiPageUtil<>(query).setLayuiPageBlank().setStartEndTime().getQuery());
    }

    /**
     * 描述:通过查询对象查询所有符合条件的数量
     *
     * @param query
     *            查询对象
     * @return Integer
     * @author DaiZhichao
     * @since 2018/10/23 16:36
     */
    @Override
    public Integer countByQuery(PartSkuPriceQuery query) {
        return partSkuPriceDAO.countByQuery(new LayuiPageUtil<>(query).setLayuiPageBlank().setStartEndTime().getQuery());
    }

    /**
     * 描述:更新实体
     *
     * @param partSkuPrice
     *            entity
     * @param staff
     *            Staff
     * @return Integer
     * @author DaiZhichao
     * @since 2018/10/23 16:37
     */
    @Override
    public Integer updateByKey(PartSkuPrice partSkuPrice, LoginStaff staff) {
        Date now = DateUtil.getNow();
        partSkuPrice.setUpdater(staff.getRealName());
        partSkuPrice.setUpdateTime(now);
        return partSkuPriceDAO.updateByKey(partSkuPrice);
    }

    /**
     * 描述:插入实体
     *
     * @param partSkuPrice
     *            entity
     * @param staff
     *            Staff
     * @return Integer
     * @author DaiZhichao
     * @since 2018/10/23 16:37
     */
    @Override
    public Integer insert(PartSkuPrice partSkuPrice, LoginStaff staff) {
        Date now = DateUtil.getNow();
        partSkuPrice.setUpdater(staff.getRealName());
        partSkuPrice.setCreater(staff.getRealName());
        partSkuPrice.setUpdateTime(now);
        partSkuPrice.setCreateTime(now);
        return partSkuPriceDAO.insert(partSkuPrice);
    }

    /**
     * 描述:删除实体
     *
     * @param skuId
     *            ID
     * @return Integer
     * @author DaiZhichao
     * @since 2018/10/23 16:37
     */
    @Override
    public Integer deleteByKey(Integer skuId) {
        return partSkuPriceDAO.deleteByKey(skuId);
    }

}
